package com.example.springjpa.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: zsw
 * @time: 2021/7/31 9:36
 */
@Configuration
public class QueueConfig {
    @Bean(name = "confirmTestFanoutQueue")
    public Queue confirmTestFanoutQueue() {
        return new Queue("confirm_test_queue", true, false, false);
    }

    @Bean(name = "confirmFanoutExchange")
    public FanoutExchange confirmTestFanoutExchange() {

        return new FanoutExchange("confirmFanoutExchange"
        );
    }

    @Bean
    public Binding confirmTestFanoutExchangeAndQueue(@Qualifier("confirmFanoutExchange") FanoutExchange confirmTestExchange,
                                                     @Qualifier("confirmTestFanoutQueue") Queue confirmTestQueue) {
        return BindingBuilder.bind(confirmTestQueue).to(confirmTestExchange);
    }


    @Bean(name = "confirmTestQueue")
    public Queue confirmTestQueue() {
        return new Queue("confirm_test_queue", true, false, false);
    }

    @Bean(name = "confirmTestExchange")
    public DirectExchange confirmTestExchange() {

        return new DirectExchange("confirmTestExchange"
        );
    }
    @Bean
    public BindingBuilder.DirectExchangeRoutingKeyConfigurer confirmTestDirectExchangeAndQueue(@Qualifier("confirmTestExchange") DirectExchange confirmTestExchange,
                                                                                               @Qualifier("confirmTestQueue") Queue confirmTestQueue) {
        return BindingBuilder.bind(confirmTestQueue).to(confirmTestExchange);
    }
}
